<script type="text/javascript">
    $(function () {
        $.fn.dataGridOptions.formSubFun("#form", '/modules/column/banner/addBanner.html');
    });
</script>
<form id="form" method="post" enctype="multipart/form-data">
    <div class="popForm sForm">

        <div class="formitm">
            <label class="lab">图片类型：</label>

            <div class="ipt">
                <select name="bannnerName" id="bannnerName" onchange="showImage()";>
                    <option value="0" selected="selected">--</option>
                    <option value="investActivityBanner">投资活动活动页面</option>
                </select>
            </div>
        </div>

    </div>

    <div class="borrowForm">
        <h1 class="borrowFormTitle">图片上传</h1>

        <div id="uploadGuaranteeBox" class="uploadWrap" data-arr="uploadFile">
            <ul id="borrowPagePic" class="photoUpload">
                <li class="addFileBtn">
                    <input type="file" name="file" class="uploadFileInput" id="uploadFile" onchange="return fileUpload();" title="点击上传图片"/>
                </li>
            </ul>
        </div>
    </div>
    <input name="webUrl" id="webUrl" value="${webUrl!}" type="hidden">
</form>
<script type="text/javascript">seajs.use("${theme_dir}/js/ajaxfileupload");
seajs.use("${theme_dir}/js/upload");</script>
<script type="text/javascript">seajs.use("/plugins/layer/layer.min");
seajs.use("/plugins/layer/skin/layer.css");</script>

<!-- 图片预览-->
<script type="text/javascript">
    $(".fileshow").fancybox();

    function fileUpload() {
        var bannnerName = $('#bannnerName').val();
        if($('#registeredActivityBanner')){
            $('#registeredActivityBanner').remove();
        }
        if($('#loginActivityBanner')){
            $('#loginActivityBanner').remove();
        }
        if($('#investActivityBanner')){
            $('#investActivityBanner').remove();
        }
        if(bannnerName==0){
            alert("请选择上传类型");
            return;
        }
        $.ajaxFileUpload({
            url: "/modules/column/banner/addBanner.html",
            secureuri: false,
            dataType: 'json',
            async:'false',
            fileElementId:'uploadFile',
            data:{bannnerName:bannnerName},
            success: function(data) {
                setTimeout(function(){  if(data.result==true){
                    var sHtml = "";
                    sHtml += '<li data-mum="' + bannnerName + '" id="' + bannnerName + '">';
                    sHtml += '<a href="' + data.webUrl + data.picPath + "?time="+new Date().getTime()+'" class="fileshow"><img src="' + data.webUrl + data.picPath  + "?time="+new Date().getTime()+'" alt=""></a>';
                    sHtml += '</li>';
                    $("#uploadFile").parents("ul").append(sHtml);

                }else{
                    alert("上传文件失败，请重试!");
                }},2500)

            },
            error: function(data,status, e) {
                debugger;
                alert("上传文件失败，请重试!");
            }
        });
    }
    
    function showImage() {
        debugger;
        if($('#registeredActivityBanner')){
            $('#registeredActivityBanner').remove();
        }
        if($('#loginActivityBanner')){
            $('#loginActivityBanner').remove();
        }
        if($('#investActivityBanner')){
            $('#investActivityBanner').remove();
        }
        var bannnerName = $('#bannnerName').val();
        var catalog = "/data/img/audition/";
        if (bannnerName!="0"){
            var pictureUrl =$("#webUrl").val()+catalog+bannnerName+".png";
            var sHtml = "";
            sHtml += '<li data-mum="' + bannnerName + '" id="' + bannnerName + '">';
            sHtml += '<a href="' + pictureUrl+ "?time="+new Date().getTime()+'" class="fileshow"><img src="' + pictureUrl + "?time="+new Date().getTime()+'" alt="" onerror="return func($(this));"></a>';
            sHtml += '</li>';
            $("#uploadFile").parents("ul").append(sHtml);
        }
    }

    function func(obj) {
        obj.parents("a").parents("li").attr("style","display:none");
    }
</script>


